import Vue from 'vue'
import Vuex from 'vuex'

//导入操作本地数据模块
import { getItem, setItem } from '@/utils/storage'

Vue.use(Vuex)

var TOKEN_KEY = 'TOUTIAO_USER'

export default new Vuex.Store({
    state: {
        // 用户的登录信息
        user: getItem(TOKEN_KEY)
    },
    mutations: {
        setUser(state, data) {
            state.user = data;
            // 为了防止刷新丢失,将token保存到本地
            setItem(TOKEN_KEY, state.user)
        }
    },
    actions: {},
    modules: {}
})